<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="/res/css/amazeui.min.css" />
		<link rel="stylesheet" href="/res/css/admin.css" />
	</head>

	<body>
		<div class="admin-content-body">
			<div class="am-cf am-padding am-padding-bottom-0">
				<div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">添加企业信息</strong><small></small></div>
			</div>
			<hr>
			<div class="am-g">
				<div class="am-u-sm-12">
					<form class="am-form" action="/company/pc/add" onsubmit="return checkData()" method="post">
						<table class="am-table am-table-striped am-table-hover table-main">
							<tbody>
								<tr>
									<td>名称</td>
									<td><input type="text" name="name" id="name" placeholder="请输入名称" /></td>
								</tr>
								<tr>
									<td>联系人</td>
									<td><input type="text" name="contact" id="contact" placeholder="请输入联系人" /></td>
								</tr>
								<tr>
									<td>电话</td>
									<td><input type="text" name="phone" id="phone" placeholder="请输入联系电话" /></td>
								</tr>
								<tr>
									<td>行业</td>
									<td><input type="text" name="serviceTrade" id="serviceTrade" placeholder="请输入公司服务行业" /></td>
								</tr>
								<tr>
									<td>地址</td>
									<td><input type="text" name="address" id="address" placeholder="请输入联系地址" /></td>
								</tr>
								<tr>
									<td>邮箱</td>
									<td><input type="email" name="email" id="email" placeholder="请输入邮箱地址" onblur="checkMail()" onfocus="clean()" /><span id="warning" style="color: red"></span></td>
								</tr>
								<tr>
									<td>密码</td>
									<td><input type="password" name="password" id="password" placeholder="请输入登录密码" /></td>
								</tr>
							</tbody>
						</table>
						<button type="submit" class="am-btn am-btn-success" >提交</button>
					</form>
				</div>
			</div>
		</div>
	</body>
	<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
	<script>

        function isEmail(mail) {
            var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (filter.test(mail)) {
                return true;
            } else {
                return false;
            }
        }

        function clean() {
            $('#warning').html('');
        }

		function checkMail(){
                var email = document.getElementById("email").value;

                if(email==null||email==''||email.trim().length==0){
                    return;
                }
                if(!isEmail(email)){
                    $('#warning').html('邮箱格式有误，请重新输入');
                    return;
				}

                $.ajax({
                    type: "get",
                    url: "/company/pc/add/check",
                    data: "email=" + email,
                    dataType: 'html',
                    contentType: "application/x-www-form-urlencoded; charset=utf-8",
                    success: function(result) {
						result = JSON.parse(result);

                        if(result["head"]["code"]!=0){
                            //alert(result['head']['msg']);
                            $('#warning').html(result['head']['msg']);
                            return false;
                        }
                        //location.reload();
                    }
                });

		}




		function checkData() {
			var name = document.getElementById("name").value;
			var contact = document.getElementById("contact").value;
			var phone = document.getElementById("phone").value;
			var serviceTrade = document.getElementById("serviceTrade").value;
			var address = document.getElementById("address").value;
			var email = document.getElementById("email").value;
			var password = document.getElementById("password").value;

			if(name==null||name==''||name.trim().length==0){
				alert("名称不能为空");
				return false;
			}
			if(contact==null||contact==''||contact.trim().length==0){
				alert("联系人不能为空");
				return false;
			}
			if(phone==null||phone==''||phone.trim().length==0||phone.trim().length<11){
				alert("联系电话格式有误，请重新输入！");
				return false;
			}
			if(serviceTrade==null||serviceTrade==''||serviceTrade.trim().length==0){
				alert("服务行业不能为空");
				return false;
			}
			if(address==null||address==''||address.trim().length==0){
				alert("联系地址不能为空");
				return false;
			}
			if(email==null||email==''||email.trim().length==0){
				alert("邮箱地址不能为空");
				return false;
			}
			if(password==null||password==''||password.trim().length==0){
				alert("密码不能为空");
				return false;
			}
			if(password.length<6){
				alert("密码长度不能小于6位！");
				return false;
			}

			return true;
		}
	</script>
</html>